home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / strlist3 / 411 Files / StrListHelp next >
Text File  |  1996-02-26  |  42KB  |  1,258 lines

  1. æKY CopyrightNoticeStrListHelp
  2. æC -----
  3.     StrListHelp Copyright (c) 1995, 1996 by John Montbriand.  All rights reserved.
  4.  
  5. æKY StrListHelp
  6. æKL StrList.h
  7.  
  8. æKY StrList.h
  9. StrList
  10. æC -----
  11. Routines for working with string lists. 
  12. Copyright (c) 1995, 1996 by John Montbriand.  All rights reserved.
  13.  
  14. creating string lists:                retrieving STR# resources:
  15.    NewStringList                          GetStringList
  16.    MakeStringList                         Get1StringList
  17.     
  18. retrieving information:               recovering storage:
  19.     StringListSize                        DisposeStringList
  20.     StringListElt                    
  21.     RetrieveIndString                 sorted map access:
  22. mapped access:                            MakeSortedStringListMap
  23.     MakeStringListMap                     WithSortedStringList
  24.     MapStringListElt                    
  25.     WithStringList                    adding new strings:
  26.                                           StringListInstall
  27. deleting strings:                         StringListAppend
  28.     StringListRemove                      StringListPrepend
  29.      ClearStringList                        
  30.                                       finding strings:
  31. adding strings to sorted lists:           FindStringList
  32.     StringListInsert                    
  33.     StringListRInsert                 operations on sets of strings:
  34.                                           StringListUnion
  35. string list -> menu handle:               StringListIntersection
  36.     StringListToMenu                      StringListDifference
  37.                                           StringListSubset
  38. string list -> ListHandle                 StringListEquivalent
  39.     StringListToList
  40.  
  41.  
  42. æKY NewStringList
  43. æFc strlist.h
  44. æMM
  45. æD Handle NewStringList(void);
  46. æDT Handle st = NewStringList();
  47. æT Function
  48. æC -----
  49. for creating a new, empty string list.
  50.  
  51.     arguments:
  52.         none
  53.     
  54.     return value:
  55.         A Handle containing a empty string list. 
  56.         if an error occurs, NULL is returned.
  57.         
  58.     description:
  59.         NewStringList creates a new string list handle in the current
  60.         heap zone.  The string list created contains no strings, and the
  61.         count value is set to zero.
  62.  
  63.     example application:
  64.         In this example, we create a new, empty string list:
  65.     
  66.         {   Handle my_string_list;
  67.             
  68.             my_string_list = NewStringList();
  69.             ...
  70.     notes:
  71.         you can call DisposeHandle to dispose of a string list created by
  72.         NewStringList.
  73.  
  74.  
  75. æKY MakeStringList
  76. æFc strlist.h
  77. æMM
  78. æD Handle MakeStringList(long n, ...);
  79. æDT Handle st = MakeStringList((long) n, ...);
  80. æT Function
  81. æC -----
  82. for creating a string list with elements specified as arguments.
  83.  
  84.     arguments:
  85.         n = the number of c style strings that follow in the ... parameter list
  86.         ... = n c style strings
  87.     
  88.     return value:
  89.         A Handle to a string list containing the strings specified in the ...
  90.         parameter list in the same order as they were provided as parameters. 
  91.         if an error occurs, NULL is returned.
  92.             
  93.     description:
  94.         MakeStringList creates a new string list handle in the current
  95.         heap zone containing the strings provided as parameters.  the
  96.         number of strings provided as parameters must match the number
  97.         of specified in the value n.  if an error occurs, NULL is returned.
  98.  
  99.     example application:
  100.         in this example we create a string list containing 5 elements:
  101.     
  102.         {   Handle my_string_list;
  103.             
  104.             my_string_list = MakeStringList(5, "this", "is", "a", "string",
  105.                  "list");
  106.             ...
  107.     notes:
  108.         you can call DisposeHandle to dispose of a string list created by
  109.         MakeStringList.
  110.  
  111.  
  112. æKY GetStringList
  113. æFc strlist.h
  114. æMM
  115. æD Handle GetStringList(short id);
  116. æDT Handle st = GetStringList((short) id);
  117. æT Function
  118. æC -----
  119. for retrieving a string list from a resource file.
  120.  
  121.     arguments:
  122.         id = the resource id of the STR# resource containing the string list
  123.     
  124.     return value:
  125.         A Handle to a string list resource or NULL if an error occurs.
  126.             
  127.     description:
  128.         GetStringList is equivalent to GetResource('STR#', id).
  129.  
  130.     example application:
  131.         in this example, we retrieve the string list with id 128:
  132.     
  133.         {   Handle my_string_list;
  134.             
  135.             my_string_list = GetStringList(128);
  136.             ...
  137.     notes:
  138.         you should not call DisposeHandle to dispose of a string list
  139.         retrieved by GetStringList as such string lists are registed
  140.         in the resource file.  Instead, after you are done with the string
  141.         list call ReleaseResource(<the string list>).
  142.         You can call DisposeStringList on a string list created by
  143.         GetStringList.
  144.  
  145.  
  146. æKY Get1StringList
  147. æFc strlist.h
  148. æMM
  149. æD Handle Get1StringList(short id);
  150. æDT Handle st = Get1StringList((short) id);
  151. æT Function
  152. æC -----
  153. for retrieving a string list from the current resource file.
  154.  
  155.     arguments:
  156.         id = the resource id of the STR# resource containing the string list
  157.     
  158.     return value:
  159.         A Handle to a string list resource or NULL if an error occurs.
  160.             
  161.     description:
  162.         Get1StringList is equivalent to Get1Resource('STR#', id) and hence
  163.         it only searches the current resource file for string list resources.
  164.  
  165.     example application:
  166.         in this example, we retrieve the string list with id 128
  167.     searching only the current resource file:
  168.     
  169.         {   Handle my_string_list;
  170.             
  171.             my_string_list = GetStringList(128);
  172.             
  173.             ...
  174.     notes:
  175.         you should not call DisposeHandle to dispose of a string list
  176.         retrieved by Get1StringList as such string lists are registed
  177.         in the resource file.  Instead, after you are done with the string
  178.         list call ReleaseResource(<the string list>).
  179.         You can call DisposeStringList on a string list created by
  180.         GetStringList.
  181.  
  182.  
  183. æKY DisposeStringList
  184. æFc strlist.h
  185. æMM
  186. æD void DisposeStringList(Handle list);
  187. æDT DisposeStringList((Handle) list);
  188. æT Procedure
  189. æC -----
  190.  
  191.     arguments:
  192.         list = a handle to a string list created by NewStringList,
  193.             MakeStringList, GetStringList, or Get1StringList.
  194.     
  195.     return value:
  196.         none.
  197.             
  198.     description:
  199.         DisposeStringList recovers the memory occupied by a string list.
  200.         After determining if the handle refers to a resource by checking
  201.         the handle's flag values, DisposeStringList either calls
  202.         ReleaseResource for resource handles or calls DisposeHandle
  203.         for regular handles.
  204.  
  205.     example application:
  206.         Here, we a get a string list from a resource file, and
  207.         and do away with it, then we create a new string list and
  208.         do away with it as well.  Note:  DisposeStringList does
  209.         the right thing in both cases calling ReleaseResource for
  210.         the resource handle and calling DisposeHandle for the list
  211.         we allocated in memory ourselves.
  212.     
  213.         {   Handle my_string_list;
  214.             
  215.             my_string_list = GetStringList(128);
  216.             if (my_string_list != NULL) {
  217.                 
  218.                 ...some statements using the string list...
  219.             
  220.                 DisposeStringList(my_string_list);
  221.             }
  222.             
  223.             my_string_list = MakeStringList(5, "this", "is", "a",
  224.                   "string", "list");
  225.             if (my_string_list != NULL) {
  226.                 
  227.                 ...some statements using the string list...
  228.                 
  229.                 DisposeStringList(my_string_list);
  230.             }
  231.             ...
  232.     notes:
  233.         none.
  234.  
  235.  
  236. æKY StringListSize
  237. æFc strlist.h
  238. æMM
  239. æD short StringListSize(Handle list);
  240. æDT short the_size = StringListSize((Handle) list);
  241. æT Function
  242. æC -----
  243. for retrieving the size of a string list.
  244.  
  245.     arguments:
  246.         list = a handle to a string list created by NewStringList,
  247.             MakeStringList, GetStringList, or Get1StringList.
  248.     
  249.     return value:
  250.         the number of strings contained in the string list parameter.
  251.             
  252.     description:
  253.         StringListSize returns the value stored in the count field of the
  254.         string list handle.  the number returned corresponds to the number
  255.         of strings stored in the list.
  256.  
  257.     example application:
  258.         here we get a string list resource and calculate it's size.
  259.     
  260.         {   Handle my_string_list;
  261.             short number_of_strings;
  262.             
  263.             my_string_list = GetStringList(128);
  264.             
  265.             number_of_strings = StringListSize(my_string_list);
  266.             ...
  267.     notes:
  268.         none.
  269.  
  270.  
  271. æKY StringListElt
  272. æFc strlist.h
  273. æMM
  274. æD StringPtr StringListElt(Handle list, short elt);
  275. æDT StringPtr the_string = StringListElt((Handle) list, (short) elt);
  276. æT Function
  277. æC -----
  278. for retrieving a pointer to a string in a string list.
  279.  
  280.     formal declaration:
  281.         StringPtr StringListElt(Handle list, short elt);
  282.     
  283.     arguments:
  284.         list = a handle to a string list created by NewStringList,
  285.             MakeStringList, GetStringList, or Get1StringList.
  286.         elt = the index of the string list element.  remember, elements
  287.             in string lists are indexed 1, 2, 3, ..., n.
  288.     
  289.     return value:
  290.         a pointer to the requested string list element or NULL if elt.
  291.             
  292.     description:
  293.         StringListElt returns a pointer to a specific element in the string
  294.         list handle.  The pointer returned refers directly to the data inside
  295.         of the string list handle.
  296.  
  297.     example application:
  298.         Here, we draw every element in a string list.  Note the calls
  299.         to HLock and HUnlock surrounding the part where we access the
  300.         strings.
  301.     
  302.         {   Handle my_string_list;
  303.             short number_of_strings, index;
  304.             StringPtr a_string;
  305.             
  306.             my_string_list = GetStringList(128);
  307.             
  308.             number_of_strings = StringListSize(my_string_list);
  309.             
  310.             HLock(my_string_list); /* lock the handle so it does not move */
  311.             
  312.             for (index = 1; index <=  number_of_strings; index++) {
  313.                 
  314.                 a_string = StringListElt(my_string_list, index);
  315.                 
  316.                 MoveTo(10, index*20);
  317.                 DrawString(a_string);
  318.             }
  319.             
  320.             HUnlock(my_string_list);
  321.             ...
  322.     notes:
  323.         StringListElt returns a pointer that refers to data stored inside
  324.         of the string list handle.  Some toolbox calls can cause handles
  325.         to move in memory and invalidate this pointer unless the string
  326.         list handle is locked. Also, the pointer returned may not always
  327.         be alligned at an even address.
  328.         
  329.         Each call to StringListElt involves a linear search of the string
  330.         list for the element requested.  If you are frequently accessing
  331.         strings stored in a string list and you are noticing a performance
  332.         dropoff because of this, then you should call MakeStringListMap
  333.         and access the strings directly using the MapStringListElt routine
  334.         (StringListElt is uses O(n) time per lookup while MapStringListElt
  335.         uses O(k) time per lookup).  For example, the example application
  336.         in StringListElt requires O(n*n) time while the example application
  337.         of MakeStringListMap only requires O(n) time for the same task, and
  338.         MakeSortedStringListMap only requires O(nlogn) time.
  339.  
  340.  
  341. æKY RetrieveIndString
  342. æFc strlist.h
  343. æMM
  344. æD void RetrieveIndString(Handle list, short elt, StringPtr the_string);
  345. æDT StringPtr st = RetrieveIndString((Handle) width, (short) elt, (StringPtr) the_string);
  346. æT Function
  347. æC -----
  348. for retrieving a string from a string list handle. 
  349.  
  350.     arguments:
  351.         list = a handle to a string list created by NewStringList,
  352.             MakeStringList, GetStringList, or Get1StringList.
  353.         elt = the index of the string list element.  remember, elements
  354.             in string lists are indexed 1, 2, 3, ..., n.
  355.     the_string = a pointer to a variable of type Str255 to copy
  356.         the string into.
  357.         
  358.     return value:
  359.         the_string, or NULL if the elt was out of bounds.
  360.             
  361.     description:
  362.         RetrieveIndString copies the indicated string list element from
  363.         the string list into the string pointed to by the_string.
  364.         RetrieveIndString returns the value passed in the third
  365.         parameter, or NULL if the index was out of bounds.
  366.  
  367.     example application:
  368.         here, we copy element 4 from the string list into the
  369.         string variable my_string:
  370.     
  371.         {    Handle my_string_list;
  372.              Str255 my_string;
  373.          
  374.              my_string_list = GetStringList(128);
  375.              RetrieveIndString(my_string_list, 4, my_string);
  376.              ...
  377.         
  378.     notes:
  379.         you do not have to lock the string list when using this
  380.         call to retrieve string list elements.
  381.  
  382.  
  383. æKY MakeStringListMap
  384. æFc strlist.h
  385. æMM
  386. æD StringPtr** MakeStringListMap(Handle list);
  387. æDT StringPtr **the_map = MakeStringListMap((Handle) list);
  388. æT Function
  389. æC -----
  390. for making a list of pointers referring to elements in a string list.
  391.  
  392.     formal declaration:
  393.         StringPtr** MakeStringListMap(Handle list);
  394.     
  395.     arguments:
  396.         list = a handle to a string list created by NewStringList,
  397.             MakeStringList, GetStringList, or Get1StringList.
  398.         
  399.     return value:
  400.         a handle to an array of string pointers.
  401.             
  402.     description:
  403.         MakeStringListMap creates an array of string pointers referring to
  404.         consecutive string list elements.  The string list is locked high in
  405.         the heap before the mapping array is created.  A map created in this
  406.         way can be used to directly access string list elements using the
  407.         function MapStringListElt without the linear search overhead required
  408.         by StringListElt.
  409.  
  410.     example application:
  411.         in this example, we use a string list map to consecutively
  412.         draw string list elements on the screen.
  413.         {   Handle my_string_list;
  414.             StringPtr** the_map, the_string;
  415.             short number_of_strings, i;
  416.             
  417.             my_string_list = NewStringList();
  418.             
  419.             ...several hundred strings are added here...
  420.             
  421.             the_map = MakeStringListMap(my_string_list);
  422.             if (the_map != NULL) {
  423.                 number_of_strings = StringListSize(my_string_list);
  424.     
  425.                 for (i=1; i <= number_of_strings; i++) {
  426.                     
  427.                     the_string = MapStringListElt(the_map, i);
  428.                     
  429.                     MoveTo(10, i*10);
  430.                     DrawString(the_string);
  431.                 }
  432.                 HUnlock(my_string_list);
  433.                 DisposeHandle((Handle) the_map);
  434.             }
  435.             ...
  436.     notes:
  437.         a map created by MakeStringListMap can be disposed of with
  438.         a call to DisposeHandle((Handle) the_map).
  439.         Since MakeStringListMap locks the string list handle, you
  440.         should remember to unlock the handle once you dispose of the map.
  441.     also note:
  442.         do not unlock the string list handle until you are completely
  443.         done with the map--unlocking the string list will invalidate
  444.         pointers stored in the map.
  445.  
  446.  
  447. æKY MakeSortedStringListMap
  448. æFc strlist.h
  449. æMM
  450. æD StringPtr** MakeSortedStringListMap(Handle list);
  451. æDT StringPtr **the_map = MakeSortedStringListMap((Handle) list);
  452. æT Function
  453. æC -----
  454. for making a list of pointers referring to elements in a string list
  455. in alphabetical order.
  456.     
  457.     arguments:
  458.         list = a handle to a string list created by NewStringList,
  459.             MakeStringList, GetStringList, or Get1StringList.
  460.         
  461.     return value:
  462.         a handle to an array of string pointers with the pointers sorted
  463.         so that the map refers to the strings in the string list in
  464.         alphabetical order.  if SLUSECASE is true, case sensitive ordering
  465.         is used.
  466.             
  467.     description:
  468.         MakeSortedStringListMap is identical to MakeStringListMap except
  469.         that the pointers in the map are sorted  so that they refer
  470.         to the string in the string list in aphabetical order.  
  471.  
  472.     example application:
  473.         in this example, we use a string list map to consecutively
  474.         draw string list elements on the screen in alphabetical order.
  475.         {   Handle my_string_list;
  476.             StringPtr** the_map, the_string;
  477.             short number_of_strings, i;
  478.             
  479.             my_string_list = NewStringList();
  480.             
  481.             ...several hundred strings are added here...
  482.             
  483.             the_map = MakeSortedStringListMap(my_string_list);
  484.             if (the_map != NULL) {
  485.                 number_of_strings = StringListSize(my_string_list);
  486.     
  487.                 for (i=1; i <= number_of_strings; i++) {
  488.                     
  489.                     the_string = MapStringListElt(the_map, i);
  490.                     
  491.                     MoveTo(10, i*10);
  492.                     DrawString(the_string);
  493.                 }
  494.                 HUnlock(my_string_list);
  495.                 DisposeHandle((Handle) the_map);
  496.             }
  497.             ...
  498.     notes:
  499.         a map created by MakeSortedStringListMap can be disposed of with
  500.         a call to DisposeHandle((Handle) the_map).
  501.         Since MakeSortedStringListMap locks the string list handle, you
  502.         should remember to unlock the handle once you dispose of the map.
  503.     also note:
  504.         do not unlock the string list handle until you are completely
  505.         done with the map--unlocking the string list will invalidate
  506.         pointers stored in the map.
  507.  
  508.  
  509. æKY WithStringList
  510. æFc strlist.h
  511. æMM
  512. æD #define WithStringList(stringlist, map)
  513. æDT WithStringList(((Handle) stringlist), ((StringPtr**) map)) { statement... }
  514. æT Macro
  515. æC -----
  516. for automatic creation of a string list map.
  517.  
  518.     arguments:
  519.         stringlist = an value of type string list.
  520.         map = a variable of type StringPtr** for use in the macro.
  521.             you do not need to initialize this variable, all you do is
  522.             declare it.
  523.  
  524.     return value:
  525.         not applicable.
  526.  
  527.     description:
  528.         WithStringList creates a map for the string list that will be
  529.         available for use in the statement immediately following the
  530.         macro invocation.  In addition, the macro disposes of the map and
  531.         unlocks the list once the statement has completed execution.  It is
  532.         usually most convienient to follow the macro with a compound
  533.         statement.
  534.  
  535.     example application:
  536.         here, we use the WithStringList macro to create a map then we
  537.         use the map to display the strings on the screen.
  538.     
  539.         {   Handle my_string_list;
  540.             StringPtr** the_map;
  541.             short number_of_strings, index;
  542.             
  543.             my_string_list = MakeStringList(4, "red", "green",
  544.                 "orange", "blue");
  545.             
  546.             WithStringList(my_string_list, the_map) {
  547.                 
  548.                 number_of_strings = StringListSize(my_string_list);
  549.                 for (i=1; i <= number_of_strings; i++) {
  550.                     MoveTo(10, i*10);
  551.                     DrawString(MapStringListElt(the_map, i));
  552.                 }
  553.             
  554.             }
  555.             ...            
  556.     notes:
  557.         macro parameters may be evaluated more than once in the macro
  558.         output so it's best to use variables here as in the above example.
  559.  
  560.  
  561. æKY WithSortedStringList
  562. æFc strlist.h
  563. æMM
  564. æD #define WithSortedStringList(stringlist, map)
  565. æDT WithSortedStringList(((Handle) stringlist), ((StringPtr**) map)) { statement... }
  566. æT Macro
  567. æC -----
  568. for automatic creation of a sorted list map.
  569.  
  570.     arguments:
  571.         stringlist = an value of type string list.
  572.         map = a variable of type StringPtr** for use in the macro.
  573.             you do not need to initialize this variable, all you do is
  574.             declare it.
  575.  
  576.     return value:
  577.         not applicable.
  578.  
  579.     description:
  580.         WithSortedStringList creates a map for the string list that will
  581.         be available for use in the statement immediately following the
  582.         macro invocation.  the pointers in the list are sorted so that 
  583.         the map refers to the strings in the list in alphabetical order. 
  584.         if SLUSECASE is true, case sensitive comparisons are used in 
  585.         ordering the map pointers.  In addition, the macro disposes 
  586.         of the map and unlocks the list once the statement has completed 
  587.         execution.  It is usually more convienient to follow the macro 
  588.         with a compound statement.
  589.  
  590.     example application:
  591.         Here, we use the WithSortedStringList macro to create a list of
  592.         strings, and then we use the map to display those strings on
  593.         the screen in alphabetical order.
  594.     
  595.         {   Handle my_string_list;
  596.             StringPtr** the_map;
  597.             short number_of_strings, index;
  598.             
  599.             my_string_list = MakeStringList(4, "red", "green",
  600.                 "orange", "blue");
  601.             
  602.             WithSortedStringList(my_string_list, the_map) {
  603.                 
  604.                 number_of_strings = StringListSize(my_string_list);
  605.                 for (i=1; i <= number_of_strings; i++) {
  606.                     MoveTo(10, i*10);
  607.                     DrawString(MapStringListElt(the_map, i));
  608.                 }
  609.             
  610.             }
  611.             ...            
  612.     notes:
  613.         macro parameters may be evaluated more than once in the macro
  614.         output so it's best to use variables here as in the above example.
  615.  
  616.  
  617. æKY StringListRemove
  618. æFc strlist.h
  619. æMM
  620. æD void StringListRemove(Handle list, short elt);
  621. æDT StringListRemove((Handle) list, (short) elt);
  622. æT Procedure
  623. æC -----
  624. for removing an element from a string list
  625.     
  626.     arguments:
  627.         list = a handle to a string list created by NewStringList,
  628.             MakeStringList, GetStringList, or Get1StringList.
  629.         elt = the index of the string list element.  remember, elements
  630.             in string lists are indexed 1, 2, 3, ..., n.
  631.         
  632.     return value:
  633.         none. 
  634.             
  635.     description:
  636.         StringListRemove deletes the specified element from the string list
  637.         updating the count field appropriately.
  638.  
  639.     example application:
  640.         here, we remove element 4 from a string list.
  641.     
  642.         {   Handle my_string_list;
  643.                         
  644.             my_string_list = MakeStringList(4, "red", "green",
  645.                 "orange", "blue");
  646.             
  647.             StringListRemove(my_string_list, 3);  /* remove the word "orange" */
  648.             ...
  649.     notes:
  650.         none.
  651.  
  652.  
  653. æKY ClearStringList
  654. æFc strlist.h
  655. æMM
  656. æD void ClearStringList(Handle list);
  657. æDT ClearStringList((Handle) list);
  658. æT Procedure
  659. æC -----
  660. for removing all elements from a string list
  661.     
  662.     arguments:
  663.         list = a handle to a string list created by NewStringList,
  664.             MakeStringList, GetStringList, or Get1StringList.
  665.         
  666.     return value:
  667.         none. 
  668.             
  669.     description:
  670.         ClearStringList removes all of the strings from the string list
  671.         making it an empty list.
  672.  
  673.     example application:
  674.         here, we clear the string list so it contains no elements.
  675.     
  676.         {   Handle my_string_list;
  677.                         
  678.             my_string_list = MakeStringList(4, "red", "green",
  679.                 "orange", "blue");
  680.             
  681.             ClearStringList(my_string_list);
  682.             ...
  683.     notes:
  684.         none.
  685.  
  686.  
  687. æKY StringListInstall
  688. æFc strlist.h
  689. æMM
  690. æD void StringListInstall(Handle list, short elt, StringPtr s);
  691. æDT StringListInstall((Handle) list, (short) elt, (StringPtr) s);
  692. æT Procedure
  693. æC -----
  694. for installing a string in a string list at a particular position.
  695.     
  696.     arguments:
  697.         list = a handle to a string list created by NewStringList,
  698.             MakeStringList, GetStringList, or Get1StringList.
  699.         elt = the index where the string list element will be placed.
  700.             remember, elements in string lists are indexed 1, 2, 3, ..., n.
  701.         s = a pointer to the string to add to the list
  702.         
  703.     return value:
  704.         none. 
  705.             
  706.     description:
  707.         StringListInstall installs a string into the string list at the
  708.         indicated element position.
  709.  
  710.     example application:
  711.         Here, we insert a string into the list at position 2.
  712.     
  713.         {   Handle my_string_list;
  714.                         
  715.             my_string_list = MakeStringList(3, "the", "brown", "fox");
  716.             
  717.             /* my_string_list =  ("the", "brown", "fox") */
  718.             
  719.             StringListInstall(my_string_list, 2, "\pquick");
  720.             
  721.             /* my_string_list =  ("the", "quick", "brown", "fox") */
  722.             ...
  723.     notes:
  724.         none.
  725.  
  726.  
  727. æKY StringListAppend
  728. æFc strlist.h
  729. æMM
  730. æD void StringListAppend(Handle list, StringPtr s);
  731. æDT StringListAppend((Handle) list, (StringPtr) s);
  732. æT Procedure
  733. æC -----
  734. for adding a string to the end of a string list.
  735.     
  736.     arguments:
  737.         list = a handle to a string list created by NewStringList,
  738.             MakeStringList, GetStringList, or Get1StringList.
  739.         s = a pointer to the string to add to the list
  740.         
  741.     return value:
  742.         none. 
  743.             
  744.     description:
  745.         StringListAppend adds the string s to the end of the string list as
  746.         the last element in the list.
  747.  
  748.     example application:
  749.         here, we add an element to the end of a string list.
  750.     
  751.         {   Handle my_string_list;
  752.                         
  753.             my_string_list = MakeStringList(3, "my", "list", "of");
  754.             
  755.             /* my_string_list =  ("my", "list", "of") */
  756.             
  757.             StringListAppend(my_string_list, "\pstrings");
  758.             
  759.             /* my_string_list =  ("my", "list", "of", "strings") */
  760.             ...
  761.     notes:
  762.         none.
  763.  
  764.  
  765. æKY StringListPrepend
  766. æFc strlist.h
  767. æMM
  768. æD void StringListPrepend(Handle list, StringPtr s);
  769. æDT StringListPrepend((Handle) list, (StringPtr) s);
  770. æT Procedure
  771. æC -----
  772. for adding a string to the front of a string list.
  773.     
  774.     arguments:
  775.         list = a handle to a string list created by NewStringList,
  776.             MakeStringList, GetStringList, or Get1StringList.
  777.         s = a pointer to the string to add to the list
  778.         
  779.     return value:
  780.         none. 
  781.             
  782.     description:
  783.         StringListPrepend adds the string s to the string list placing it
  784.         in the first element position.
  785.  
  786.     example application:
  787.         here, we add an element to the front of the string list.
  788.     
  789.         {   Handle my_string_list;
  790.                         
  791.             my_string_list = MakeStringList(3, "heap", "of", "strings");
  792.             
  793.             /* my_string_list =  ("heap", "of", "strings") */
  794.             
  795.             StringListPrepend(my_string_list, "\pA big");
  796.             
  797.             /* my_string_list =  ("A big", "heap", "of", "strings") */
  798.             ...
  799.     notes:
  800.         none.
  801.  
  802.  
  803. æKY StringListInsert
  804. æFc strlist.h
  805. æMM
  806. æD short StringListInsert(Handle list, StringPtr s);
  807. æDT short where = StringListInsert((Handle) list, (StringPtr) s);
  808. æT Function
  809. æC -----
  810. for adding a string to an alphabetically sorted string list.
  811.  
  812.     arguments:
  813.         list = a handle to a string list created by NewStringList,
  814.             MakeStringList, GetStringList, or Get1StringList.
  815.         s = a pointer to the string to add to the list
  816.         
  817.     return value:
  818.         the position in the list of strings where the string was installed,
  819.         or zero if an error occurs.
  820.             
  821.     description:
  822.         StringListInsert adds the string to a string list that is sorted
  823.         in ascending, non case sensitive, alphabetical order in such a
  824.         way that the list remains sorted after the string has been added.
  825.  
  826.     example application:
  827.         in this example we insert the string delta into an alphabetically
  828.         sorted string list.
  829.     
  830.         {   Handle my_string_list;
  831.                         
  832.             my_string_list = MakeStringList(3, "alpha", "beta", "gamma");
  833.             
  834.             /* my_string_list =  ("alpha", "beta", "gamma") */
  835.             
  836.             StringListInsert(my_string_list, "\pdelta");
  837.             
  838.             /* my_string_list =  ("alpha", "beta", "delta", "gamma") */
  839.             ...
  840.     notes:
  841.         none.
  842.  
  843.  
  844. æKY StringListRInsert
  845. æFc strlist.h
  846. æMM
  847. æD short StringListRInsert(Handle list, StringPtr s);
  848. æDT short where = StringListRInsert((Handle) list, (StringPtr) s);
  849. æT Function
  850. æC -----
  851. for adding a string to an alphabetically sorted string list.  The list
  852. should be sorted in descending order.
  853.  
  854.     arguments:
  855.         list = a handle to a string list created by NewStringList,
  856.             MakeStringList, GetStringList, or Get1StringList.
  857.         s = a pointer to the string to add to the list
  858.         
  859.     return value:
  860.         the position in the list of strings where the string was installed,
  861.         or zero if an error occurs.
  862.             
  863.     description:
  864.         StringListRInsert adds the string to a string list that is sorted
  865.         in descending, non case sensitive, alphabetical order in such a
  866.         way that the list remains sorted after the string has been added.
  867.  
  868.     example application:
  869.         in this example we insert the string delta into an alphabetically
  870.         sorted string list.  The list is sorted in descending order.
  871.     
  872.         {   Handle my_string_list;
  873.                         
  874.             my_string_list = MakeStringList(3, "gamma", "beta", "alpha");
  875.             
  876.             /* my_string_list =  ("gamma", "beta", "alpha") */
  877.             
  878.             StringListRInsert(my_string_list, "\pdelta");
  879.             
  880.             /* my_string_list =  ("gamma", "delta", "beta", "alpha") */
  881.             ...
  882.     notes:
  883.         none.
  884.  
  885.  
  886. æKY FindStringList
  887. æFc strlist.h
  888. æMM
  889. æD short FindStringList(Handle list, StringPtr s);
  890. æDT short where = FindStringList((Handle) list, (StringPtr) s);
  891. æT Function
  892. æC -----
  893. find the string in a string list.
  894.  
  895.     arguments:
  896.         list = a handle to a string list created by NewStringList,
  897.             MakeStringList, GetStringList, or Get1StringList.
  898.         s = a pointer to the string to find in the list
  899.         
  900.     return value:
  901.         the position in the list of strings where the string was found or zero
  902.         if the string is not in the list.
  903.             
  904.     description:
  905.         FindStringList searches the list of strings in sequential order until
  906.         it finds a non case sensitive match for the string.  If a match is
  907.         the index is returned, otherwise, if there is no match, FindStringList
  908.         returns zero.
  909.  
  910.     example application:
  911.         Here, we use the FindStringList routine to find the index of the
  912.         indicated string.
  913.     
  914.         {   Handle my_string_list;
  915.             short position;
  916.             
  917.             my_string_list = MakeStringList(5, "the", "word", "is",
  918.                 "hidden", "here");
  919.                         
  920.             position = FindStringList(my_string_list, "\phidden");
  921.             if (position != 0) {
  922.                 /* position ==  4 */
  923.             }
  924.             
  925.             position = FindStringList(my_string_list, "\pUnused");
  926.                 
  927.                 /* position ==  0, 'unused' is not in the list */
  928.             ...
  929.     notes:
  930.         none.
  931.  
  932.  
  933. æKY StringListToMenu
  934. æFc strlist.h
  935. æMM
  936. æD MenuHandle StringListToMenu(Handle list, short id, StringPtr name);
  937. æDT MenuHandle themenu = StringListToMenu((Handle) list, (short) id, (StringPtr) s);
  938. æT Function
  939. æC -----
  940. create a menu containing all of the strings in the string list.
  941.     
  942.     arguments:
  943.         list = a handle to a string list created by NewStringList,
  944.             MakeStringList, GetStringList, or Get1StringList.
  945.         id = the menu id for the menu
  946.         name = the menu title, NULL is OK.
  947.         
  948.     return value:
  949.         the created menu handle.
  950.             
  951.     description:
  952.         StringListToMenu creates a new menu handle filling in the menu
  953.         items using the strings in the string list.  items in the string list
  954.         will correspond to items in the menu on a one to one basis.
  955.         i.e. string list element one will be the same as menu item one,
  956.         and so on, and so on....
  957.  
  958.     example application:
  959.         Here, we create a menu for use with the PopUpMenuSelect function..
  960.        
  961.         {   Handle my_string_list;
  962.             MenuHandle my_menu;
  963.             long result;
  964.             short item;
  965.             
  966.             my_string_list = MakeStringList(3, "Red", "Green", "Blue");
  967.             
  968.             my_menu = StringListToMenu(my_string_list, 128, "\pColours");
  969.             
  970.             InsertMenu(my_menu, -1);
  971.             result = PopUpMenuSelect(my_menu, 100, 100, 1);
  972.             DeleteMenu(128);
  973.             if (HiWord(result) != 0) {
  974.                 item = LoWord(result);
  975.                 .....
  976.             }
  977.             ...
  978.     notes:
  979.         by default, StringListToMenu calls SetItem to add the strings into the
  980.         menu handle and as such the set of special menu formatting characters
  981.         are not interpreted by the menu manager.  If you would like to have
  982.         the menu formatting characters interpreted when string list elements
  983.         are added to menus then you can define the compile time variable
  984.         INTERPRETMENUCHARS in the file "strlist.h".
  985.  
  986.  
  987. æKY StringListToList
  988. æFc strlist.h
  989. æMM
  990. æD void StringListToList(Handle list, ListHandle the_list);
  991. æDT StringListToList((Handle) list, (ListHandle) the_list);
  992. æT Procedure
  993. æC -----
  994. add strings from a string list to a list handle.
  995.     
  996.     arguments:
  997.         list = a handle to a string list created by NewStringList,
  998.             MakeStringList, GetStringList, or Get1StringList.
  999.         the_list = a list handle
  1000.         
  1001.     return value:
  1002.         none.
  1003.             
  1004.     description:
  1005.         StringListToList fills in the first column of the ListHandle so
  1006.         it contains all of the strings from the string list.
  1007.  
  1008.     example application:
  1009.         here, we copy a string list into a list manager list.
  1010.     
  1011.     {   Handle my_string_list;
  1012.             ListHandle my_list_manager_list;
  1013.             WindowPtr the_window;
  1014.             Rect bounds, dataBounds;
  1015.             Point cSize;
  1016.             
  1017.                 /* set up some stuff */
  1018.             SetPt(&cSize, 0, 0);
  1019.             SetRect(&dataBounds, 0, 0, 1, 0);
  1020.             SetRect(&bounds, 100, 100, 200, 200);
  1021.             
  1022.                 /* make a window */
  1023.             the_window = NewWindow(NULL, &bounds, "\pstrlist",
  1024.                 true, noGrowDocProc, (WindowPtr) (-1), false, 0);
  1025.             SetPort(the_window);
  1026.             
  1027.                 /* make a list */
  1028.             OffsetRect(&bounds, -bounds.left, -bounds.top);
  1029.             my_list_manager_list = LNew(&bounds, &dataBounds, cSize,
  1030.                     0, the_window, true, false, false, true);
  1031.             
  1032.                 /* make a string list */
  1033.             my_string_list = MakeStringList(3, "Red", "Green", "Blue");
  1034.             
  1035.                 /* put the string list into the list */
  1036.             StringListToList(my_string_list, my_list_manager_list);
  1037.             ...
  1038.     notes:
  1039.         recall string lists elements are indexed elt = 1, 2, ..., n while
  1040.         elements contained in ListHandles created by StringListToList are
  1041.         indexed cell.v = 0, 1, 2, ..., n-1.
  1042.  
  1043.  
  1044. æKY StringListUnion
  1045. æFc strlist.h
  1046. æMM
  1047. æD Handle StringListUnion(Handle A, Handle B);
  1048. æDT Handle the_union = StringListUnion((Handle) A, (Handle) B);
  1049. æT Function
  1050. æC -----
  1051. calculate the union of two sets of strings.
  1052.     
  1053.     arguments:
  1054.         A = a handle to a string list created by NewStringList, MakeStringList,
  1055.             GetStringList, or Get1StringList.
  1056.         B = a handle to a string list created by NewStringList, MakeStringList,
  1057.             GetStringList, or Get1StringList.
  1058.         
  1059.     return value:
  1060.         a string list handle.
  1061.             
  1062.     description:
  1063.         StringListUnion returns a new string list handle containing all
  1064.         of the strings that appear in both string list A and string list B,
  1065.         or NULL if an error occurs.  if SLUSECASE is true, case sensitive
  1066.         comparisons are used.  operation = OR
  1067.  
  1068.     example application:
  1069.         here, we calculate the union of two sets of strings.
  1070.     
  1071.         {    Handle A, B, C;
  1072.  
  1073.             A = MakeStringList(4, "red", "green", "orange", "blue");
  1074.             
  1075.             B = MakeStringList(4, "yellow", "green", "purple", "blue");
  1076.             
  1077.             C = StringListUnion(A, B);
  1078.             
  1079.             /* C now contains:
  1080.                 {"blue", "green", "orange", "purple", "red", "yellow"} */
  1081.  
  1082.             ...
  1083.     notes:
  1084.         in the present implementation, the result will be alphabetically
  1085.         sorted.
  1086.  
  1087.  
  1088. æKY StringListIntersection
  1089. æFc strlist.h
  1090. æMM
  1091. æD Handle StringListIntersection(Handle A, Handle B);
  1092. æDT Handle the_intersection = StringListIntersection((Handle) A, (Handle) B);
  1093. æT Function
  1094. æC -----
  1095. calculate the intersection of two sets of strings.
  1096.     
  1097.     arguments:
  1098.         A = a handle to a string list created by NewStringList, MakeStringList,
  1099.             GetStringList, or Get1StringList.
  1100.         B = a handle to a string list created by NewStringList, MakeStringList,
  1101.             GetStringList, or Get1StringList.
  1102.         
  1103.     return value:
  1104.         a string list handle.
  1105.             
  1106.     description:
  1107.         StringListIntersection returns a new string list handle containing only
  1108.         those strings that appear in both string list A and string list B,
  1109.         or NULL if an error occurs.  if SLUSECASE is true, case sensitive
  1110.         comparisons are used. operation = AND
  1111.  
  1112.     example application:
  1113.         here, we calculate the intersection of two sets of strings.
  1114.     
  1115.         {   Handle A, B, C;
  1116.  
  1117.             A = MakeStringList(4, "red", "green", "orange", "blue");
  1118.             
  1119.             B = MakeStringList(4, "yellow", "green", "purple", "blue");
  1120.             
  1121.             C = StringListIntersection(A, B);
  1122.             
  1123.             /* C now contains:
  1124.                 {"blue", "green"} */
  1125.  
  1126.             ...
  1127.     notes:
  1128.         in the present implementation, the result will be alphabetically
  1129.         sorted.
  1130.  
  1131.  
  1132. æKY StringListDifference
  1133. æFc strlist.h
  1134. æMM
  1135. æD Handle StringListDifference(Handle A, Handle B);
  1136. æDT Handle the_difference = StringListDifference((Handle) A, (Handle) B);
  1137. æT Function
  1138. æC -----
  1139. calculate the difference of two sets of strings.
  1140.     
  1141.     arguments:
  1142.         A = a handle to a string list created by NewStringList, MakeStringList,
  1143.             GetStringList, or Get1StringList.
  1144.         B = a handle to a string list created by NewStringList, MakeStringList,
  1145.             GetStringList, or Get1StringList.
  1146.         
  1147.     return value:
  1148.         a string list handle.
  1149.             
  1150.     description:
  1151.         StringListDifference returns a new string list handle containing all
  1152.         the strings that do not appear in both A and B.  if SLUSECASE is true,
  1153.         case sensitive comparisons are used.  operation = XOR
  1154.  
  1155.     example application:
  1156.         here, we calculate the difference of two sets of strings.
  1157.     
  1158.         {   Handle A, B, C;
  1159.  
  1160.             A = MakeStringList(4, "red", "green", "orange", "blue");
  1161.             
  1162.             B = MakeStringList(4, "yellow", "green", "purple", "blue");
  1163.             
  1164.             C = StringListDifference(A, B);
  1165.             
  1166.             /* C now contains:
  1167.                 {"orange", "purple", "red", "yellow"} */
  1168.  
  1169.             ...
  1170.     notes:
  1171.         in the present implementation, the result will be alphabetically 
  1172.         sorted.
  1173.  
  1174.  
  1175. æKY StringListSubset
  1176. æFc strlist.h
  1177. æMM
  1178. æD Boolean StringListSubset(Handle A, Handle B);
  1179. æDT Boolean is_subset = StringListSubset((Handle) A, (Handle) B);
  1180. æT Function
  1181. æC -----
  1182. determine if one set is a subset of another.
  1183.     
  1184.     arguments:
  1185.         A = a handle to a string list created by NewStringList, MakeStringList,
  1186.             GetStringList, or Get1StringList.
  1187.         B = a handle to a string list created by NewStringList, MakeStringList,
  1188.             GetStringList, or Get1StringList.
  1189.         
  1190.     return value:
  1191.         true or false.
  1192.             
  1193.     description:
  1194.         StringListSubset returns true if the strings contained in B make up
  1195.         a subset of the strings contained in A.  if SLUSECASE is true,
  1196.         case sensitive comparisons are used.
  1197.  
  1198.     example application:
  1199.         here, we call StringListSubset to determine if B is a subset of A.
  1200.     
  1201.         {   Handle A, B, C;
  1202.  
  1203.             A = MakeStringList(4, "red", "green", "orange", "blue");
  1204.             
  1205.             B = MakeStringList(4, "red", "orange", "blue");
  1206.             
  1207.             if (StringListSubset(A, B)) {
  1208.                 /* B is infact a subset of A */
  1209.             }
  1210.  
  1211.             ...
  1212.     notes:
  1213.         none.
  1214.  
  1215.  
  1216. æKY StringListEquivalent
  1217. æFc strlist.h
  1218. æMM
  1219. æD Boolean StringListEquivalent(Handle A, Handle B);
  1220. æDT Boolean the_same = StringListEquivalent((Handle) A, (Handle) B);
  1221. æT Function
  1222. æC -----
  1223. determine if two sets of strings contain the same elements.
  1224.  
  1225.     arguments:
  1226.         A = a handle to a string list created by NewStringList, MakeStringList,
  1227.             GetStringList, or Get1StringList.
  1228.         B = a handle to a string list created by NewStringList, MakeStringList,
  1229.             GetStringList, or Get1StringList.
  1230.         
  1231.     return value:
  1232.         true or false.
  1233.             
  1234.     description:
  1235.         StringListEquivalent returns true if the strings both string lists
  1236.         contain the same strings.  if SLUSECASE is true,  case sensitive
  1237.         comparisons are used.
  1238.  
  1239.     example application:
  1240.         here, we call StringListEquivalent to if the two sets are the same.
  1241.     
  1242.         {    Handle A, B;
  1243.  
  1244.             A = MakeStringList(4, "red", "green", "orange", "blue");
  1245.             
  1246.             B = MakeStringList(4, "red", "green", "orange", "blue");
  1247.             
  1248.             if (StringListEquivalent(A, B)) {
  1249.                 /* yes, the are the same sets */
  1250.             }
  1251.  
  1252.             ...
  1253.     notes:
  1254.         none.
  1255.  
  1256.  
  1257.  
  1258.